<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/general.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/mui.poppicker.css"/>
		<style type="text/css">
table{
	width: 100%;
	text-align: center;
}
tr{
	padding: 0.3em;
}
td{
	padding: 0.3em;
}
tr>td:first-child{
	width: 30%;
}
tr>td:nth-child(2){
	width: 30%;
}
tr>td:nth-child(3){
	width: 10%;
}
tr>td:nth-child(4){
	width: 30%;
}

input[type=number]{
    width: 100%;
    margin-bottom: 0;
    padding-left: 0;
    border: 0;
    border-bottom: 1px solid #c7c7c7;
    line-height: 21px;
    height: 40px;
}
.butdiv{
	min-width: 50%;
	padding: 0.2em;
	margin: auto;
	border: 1px solid #c7c7c7;
	border-radius:5px;
}
    
    
    
   

		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title">提成设置</h1>
		</header>
		<div class="mui-content">
		    <div class="maindiv">
				<table border="0" cellspacing="20" cellpadding="20">
					<tr>
						<td>充值指定</td>
						<td><input id="appoint" type="number" name="" value="" /></td>
						<td class="td">%</td>
						<td><div id="proportion" class="butdiv">
							比例
						</div></td>
					</tr>
					<tr>
						<td>非指定</td>
						<td><input id="noappoint" type="number" name="" value="" /></td>
						<td class="td">%</td>
						<td></td>
					</tr>
				</table>
				
				
				
		    </div>
		    
		    
		    <div class="maindiv">
		    	<button id="subid" type="button" class="mui-btn mui-btn-blue mui-btn-block">保存</button>
		    </div>
		</div>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/req.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.picker.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.poppicker.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var rid = 0,proportiontype = 1;
			
			var appoint = {
				appoint_money: 0,
				appoint_percent: 0,
				non_appoint_money: 0,
				non_appoint_percent: 0,
			}
			
			window.onload = function(){
				mui.init();
				rid = getrequest().rid||0;
				console.log(rid);
				mui.plusReady(function(res){
					 var view = plus.webview.currentWebview();
					 rid = view.rid||0;
				})
				var proportionPicker = new mui.PopPicker();
                proportionPicker.setData([{
                    value: 1,
                    text: '比例'
                },{
                    value: 2,
                    text: '金额'
                }]);
                var proportion = document.getElementById('proportion');
                proportion.addEventListener('tap', function(event) {
                    proportionPicker.show(function(items) {
                        proportion.innerText = items[0].text;
                        proportiontype = parseInt(items[0].value);
                        if(items[0].value == '1'){
                        	$(".td").html("%");
                        	g("appoint").value = appoint.appoint_percent;
							g("noappoint").value = appoint.non_appoint_percent;
                        }
                        if(items[0].value == '2'){
                        	$(".td").html("元");
                        	g("appoint").value = appoint.appoint_money;
							g("noappoint").value = appoint.non_appoint_money;
                        }
                        
                    });
                }, false);
                
                
				g("subid").addEventListener("tap",function(e){
					
					recharge_percent();
				})
				
				getrecharge_percent();
			}
			//设置充值提成
			function recharge_percent(){
				var data = {
					url:"/api/recharge_percent/set",
						data:{
							access_token:acctoken(),
							type:proportiontype,
							appoint_percent:proportiontype==1?g("appoint").value:"",
							non_appoint_percent:proportiontype == 1?g("noappoint").value:"",
							appoint_money:proportiontype == 2?g("appoint").value:"",
							non_appoint_money:proportiontype == 2?g("noappoint").value:""
						}
					}
				ajax(data,function(res){
					console.log("设置充值提成",res)
					mui.toast(res.msg);
					getrecharge_percent();
				})
				
			}
			//获取充值提成
			function getrecharge_percent(){
				var data = {
					url:"/api/recharge_percent/detail",
						data:{
							access_token:acctoken(),
						}
					}
				ajax(data,function(res){
					console.log("获取充值提成",res);
					var list = res.data;
					appoint.appoint_money = list.appoint_money;
					appoint.appoint_percent = list.appoint_percent;
					appoint.non_appoint_money = list.non_appoint_money;
					appoint.non_appoint_percent = list.non_appoint_percent;
					if(list&&list.type == 1){
						g("appoint").value = list.appoint_percent;
						g("noappoint").value = list.non_appoint_percent;
					}else{
						$(".td").html("元");
						g("appoint").value = list.appoint_money;
						g("noappoint").value = list.non_appoint_money;
						proportiontype = list.type;
						g("proportion").innerHTML = "金额";
					}
					
					//mui.toast(res.msg);
				})
				
			}
		</script>
	</body>

</html>